home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 May / CMCD0504.ISO / Software / Freeware / Programare / gdiplusdelphi / demos / Using Regions / Hit Testing with a Region / Unit1.pas < prev   
Encoding:
Pascal/Delphi Source File  |  2002-07-29  |  2.0 KB  |  86 lines

  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  7.   Dialogs, GDIPOBJ, GDIPAPI;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  12.       Y: Integer);
  13.     procedure FormCreate(Sender: TObject);
  14.   private
  15.     { Private declarations }
  16.   public
  17.     { Public declarations }
  18.   end;
  19.  
  20. var
  21.   Form1: TForm1;
  22.   IsIn: boolean;
  23. implementation
  24.  
  25. {$R *.dfm}
  26.  
  27. procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  28.   Y: Integer);
  29. var
  30.   graphic: TGPGraphics;
  31.   Point: TGPPoint;
  32.   solidBrush: TGPsolidBrush;
  33.   WhiteBrush : TGPsolidBrush;
  34.   region1, region2: TGPRegion;
  35.   b: boolean;
  36. begin
  37.   graphic := TGPGraphics.Create(canvas.handle);
  38.   point := MakePoint(x, y);
  39.   // Assume that the variable "point" contains the location
  40.   // of the most recent click.
  41.   // To simulate a hit, assign (60, 10) to point.
  42.   // To simulate a miss, assign (0, 0) to point.
  43.  
  44.   solidBrush:= TGPsolidBrush.Create(aclBlack);
  45.   region1:= TGPRegion.Create(MakeRect(50, 0, 50, 150));
  46.   region2:= TGPRegion.Create(MakeRect(0, 50, 150, 50));
  47.  
  48.   // Create a plus-shaped region by forming the union of region1 and region2.
  49.   // The union replaces region1.
  50.   region1.Union(region2);
  51.  
  52.   if(region1.IsVisible(point, graphic)) then
  53.   begin
  54.     // The point is in the region. Use an opaque brush.
  55.     solidBrush.SetColor(MakeColor(255, 255, 0, 0));
  56.     b := true;
  57.   end
  58.   else
  59.   begin
  60.     // The point is not in the region. Use a semitransparent brush.
  61.     solidBrush.SetColor(MakeColor(64, 255, 0, 0));
  62.     b:=false;
  63.   end;
  64.  
  65.   if b <> isIn then
  66.   begin
  67.     WhiteBrush := TGPsolidBrush.Create(aclwhite);
  68.     graphic.FillRegion(WhiteBrush, region1);
  69.     graphic.FillRegion(solidBrush, region1);
  70.     WhiteBrush.Free;
  71.     isIn := not isIn;
  72.   end;
  73.  
  74.   solidBrush.Free;
  75.   region1.Free;
  76.   graphic.Free;
  77.  
  78. end;
  79.  
  80. procedure TForm1.FormCreate(Sender: TObject);
  81. begin
  82.   IsIn:= false;
  83. end;
  84.  
  85. end.
  86.